
<script>
import ExtForm from '@/components/lt/codeGenerator/components/ExtForm'
import request from '@/utils/request'
import ExtTable from '@/components/lt/codeGenerator/components/ExtTable'
import moment from 'moment'
import {SysMixin} from '@/mixins/SysMixin'
import defaultSettings from '@/config/defaultSettings'
import pick from 'lodash.pick'
import ExtRow from '@/components/lt/codeGenerator/components/ExtRow'
import ExtDrawer from './ExtDrawer'
import ExtModal from './ExtModal'
import ExtButtonItem from '@/components/lt/codeGenerator/components/ExtButtonItem'
import ExtButton from '@/components/lt/codeGenerator/components/ExtButton'
import { Modal } from 'ant-design-vue'
import ExtDropDownButton from '@/components/lt/codeGenerator/components/ExtDropDownButton'
import {getLodop} from '/public/static/clodop/LodopFuncs'
import ExtTree from '@/components/lt/codeGenerator/components/ExtTree'
import ExtTag from '@/components/lt/codeGenerator/components/ExtTag'
import ExtGridForm from '@/components/lt/codeGenerator/components/ExtGridForm'
import ExtFormCol from '@/components/lt/codeGenerator/components/ExtFormCol'
import Big from 'big.js'
import LExcelUpload from '@/components/lt/LExcelUpload'
import LExcelDownload from '@/components/lt/LExcelDownload'
import LEditTableColumn from '@/components/lt/editTable/LEditTableColumn'
import Vue from 'vue'
import * as echarts from 'echarts'
import ExtMap from '@/components/lt/codeGenerator/components/ExtMap'
import ExtLineChar from '@/components/lt/codeGenerator/components/ExtLineChar'
import ExtBarChar from '@/components/lt/codeGenerator/components/ExtBarChar'
import ExtPieChar from '@/components/lt/codeGenerator/components/ExtPieChar'
import ExtFlow from '@/components/lt/codeGenerator/components/ExtFlow'
import {findComponentDownward,findComponentsDownward,findComponentUpward,findComponentsUpward} from '@/utils/util'
import ExtQueryForm from '@/components/lt/codeGenerator/components/ExtQueryForm'

export default {
    
    components:{ExtForm,ExtTable,ExtRow,ExtDrawer,ExtButtonItem,ExtButton,ExtDropDownButton,ExtTree,ExtTag,ExtGridForm,ExtFormCol,
        ExtModal,LExcelUpload,LExcelDownload,LEditTableColumn,ExtLineChar,ExtBarChar,ExtPieChar,ExtMap,ExtFlow,ExtQueryForm},
    mixins:[SysMixin],
   
    data(){
        return{
            findComponentDownward,
            findComponentsDownward,
            findComponentUpward,
            findComponentsUpward,
            width:800,
            defaultSettings,
            moment,
            visible:false,
            model:{},
            confirmLoading:false,
            title:'标题',
            pageMethods:null,//页面方法
            pageData:null,//页面数据
            timer:null,
            pick,
            request,
            isShowBootomButton:true,
            okButtonProps:{props: { shape:'round'}},
            cancelButtonProps:{props: { shape:'round'}},
            footer:"",
            Modal,
            LODOP:null,
            getLodop,
            Big,
            excelUploadTemplateId:'',
            excelDownloadTemplateId:'',
            excelUploadTemplateName:'',
            excelDownloadTemplateName:'',
            excelDownTable:null,
            excelDownShowColumn:true,
            excelUploadShowTemplate:true,
            excelUploadImoprtParameter:{},
            bodyStyle:{maxHeight:'70vh', overflowY: 'auto'}
  
        }
    },
    
    computed:{},
    watch:{},
    methods:{
        //动态添加监听
            // this.$watch('pageData',()=>{
            //     console.log(1111)
            // },{deep: true})
        pageEdit(){},
        edit (pageId,record) {
            // console.log(record)
            if(!pageId){
                return false
            }
            
            this.model = Object.assign({}, record)
            this.querySysPage(pageId)
        },
       
        querySysPage(pageId){
            this.confirmLoading=true
            request.get('/SysPageController/querySysPageById',{params:{pageId:pageId}}).then((res)=>{
                if (res.success) {
                    res.result.pageData = JSON.parse(require('js-base64').Base64.decode(res.result.pageData))
                    this.pageData = res.result.pageData
                    this.initDictCodes = res.result.pageDict
                    this.initSysPageMethods(this.pageData.code.methods)
                    this.initSysPageData(this.pageData.code.data)
                    this.$nextTick(() => {
                        this.visible = true
                        this.timer = setTimeout(() => {this.pageEdit()}, 100)
                    })

                } else {
                    this.$message.warning(res.message)
                }
            }).finally(()=>{
                this.confirmLoading=false
            })
        },
        
        
        ok(){
            this.close()
        },
        cancel(){
            // this.bus.$off()
            this.$bus.clear(this)
            this.visible=false
        },
        close (refreshRef) {
            // this.bus.$off()
            this.$bus.clear(this)
            if(this.timer){
                clearTimeout(this.timer)
            }
            this.$emit('close',refreshRef)
            this.visible = false
        },
       
        
    },
    render: function(h) {
        if(this.pageData){
            return(
                <a-modal destroyOnClose={true} visible={this.visible} maskClosable={true} width={this.width} title={this.title} v-drag  confirmLoading={this.confirmLoading}
                    onClose={this.cancel} onOk={this.ok} onCancel={this.cancel} okButtonProps={this.okButtonProps} cancelButtonProps={this.cancelButtonProps} bodyStyle={this.bodyStyle}>
                    <a-spin spinning={this.confirmLoading}>
                        {this.initSysPageComponents(h,this.pageData.components,this.initDictCodes)}
                    </a-spin>

                    <ExtModal ref="ExtModal" onClose={this.closeCallback}></ExtModal>
                    <LExcelUpload ref="LExcelUpload" onHandleOk={this.excelUploadCallBack} imoprtParameter={this.excelUploadImoprtParameter} isShowTemplate={this.excelUploadShowTemplate} templateId={this.excelUploadTemplateId} templateName={this.excelUploadTemplateName}></LExcelUpload>
                    <LExcelDownload ref="LExcelDownload" onHandleOk={this.excelDownCallBack} isShowColumn={this.excelDownShowColumn} downTable={this.excelDownTable} templateId={this.excelDownloadTemplateId} templateName={this.excelDownloadTemplateName}></LExcelDownload>
                </a-modal>
            )
        }
    }

}
</script>



